if ($('#priv').val() == 'Staff') {
	$("#gridDanhSachKhachHang").jqGrid({        
	   	url:'/quanlykhachhang/json/?func=getListKhachHang',
		datatype: "json",
	   	colNames:['Mã khách hàng','Tên khách hàng', 'Người liên hệ', 'Điện thoại','Địa chỉ','Quận/Huyện','Tỉnh/Thành phố', 
	   	          'Địa chỉ giao hàng', 'Mô tả khách hàng', 'Loại hình kinh doanh', 'Quy mô', 'Ghi chú', 'Chiết khấu', 
	   	          'NV giao hàng', 'Trạng thái'],
	   	colModel:[
	   		{name:'id',index:'maKH', width:55,edittype:"select"},
	   		{name:'tenKhachHang',index:'tenKhachHang', width:80,align:"right", editable:true},		
	   		{name:'nguoiLienHe',index:'nguoiLienHe', width:80, sortable:false, editable:true},
	   		{name:'dienThoai',index:'dienThoai', width:150, sortable:false, editable:true},
	   		{name:'diaChi',index:'diaChi', width:150, sortable:false, editable:true},
	   		{name:'quanHuyen',index:'quanHuyen', width:80, sortable:false, editable:true},
	   		{name:'thanhPho',index:'thanhPho', width:80, sortable:false, editable:true},
	   		{name:'diaChiGiaoHang',index:'diaChiGiaoHang', width:80, sortable:false, editable:true},
	   		{name:'moTaKhachHang',index:'moTaKhachHang', width:80, sortable:false, editable:true},
	   		{name:'loaiHinhKinhDoanh',index:'loaiHinhKinhDoanh', width:80, sortable:false, editable:true},
	   		{name:'quyMo',index:'quyMo', width:80, sortable:false, editable:true},
	   		{name:'ghiChu',index:'ghiChu', width:80, sortable:false, editable:true},
	   		{name:'chietKhau',index:'chietKhau', width:80, sortable:false, formatter:"number", editable:true},
	   		{name:'nvGiaoHang', index: 'nvGiaoHang', width:80, editable: false},
	   		{name:'trangThai',index:'trangThai', width:80, sortable:false, editable:false}
	   	],
	   	rowNum:10,
	   	rowList:[10,20,30],
	   	pager: '#pDanhSachKhachHang',
	   	sortname: 'maKH',
	    viewrecords: true,
	    loadonce: false,
	    sortorder: "desc",
		jsonReader: {
			repeatitems : false,
			id: "0"
		},
		caption: "Danh sách khách hàng",
		width: '971',
	    height: '100%',
		editurl:"/quanlykhachhang/json/?func=updateKhachHang"
	});
	jQuery("#gridDanhSachKhachHang").jqGrid('navGrid','#pDanhSachKhachHang',
										{
											add:true,
											edit:true,
											del:false
										});
}
else if ($('#priv').val() == 'Owner') {
	$("#gridDanhSachKhachHang").jqGrid({        
	   	url:'/quanlykhachhang/json/?func=getListKhachHang',
		datatype: "json",
	   	colNames:['Mã khách hàng','Tên khách hàng', 'Người liên hệ', 'Điện thoại','Địa chỉ','Quận/Huyện','Tỉnh/Thành phố', 
	   	          'Địa chỉ giao hàng', 'Mô tả khách hàng', 'Loại hình kinh doanh', 'Quy mô', 'Ghi chú', 'Chiết khấu', 
	   	          'NV giao hàng','Trạng thái'],
	   	colModel:[
	   		{name:'id',index:'maKH', width:55,edittype:"select"},
	   		{name:'tenKhachHang',index:'tenKhachHang', width:80,align:"right", editable:true},		
	   		{name:'nguoiLienHe',index:'nguoiLienHe', width:80, sortable:false, editable:true},
	   		{name:'dienThoai',index:'dienThoai', width:150, sortable:false, editable:true},
	   		{name:'diaChi',index:'diaChi', width:150, sortable:false, editable:true},
	   		{name:'quanHuyen',index:'quanHuyen', width:80, sortable:false, editable:true},
	   		{name:'thanhPho',index:'thanhPho', width:80, sortable:false, editable:true},
	   		{name:'diaChiGiaoHang',index:'diaChiGiaoHang', width:80, sortable:false, editable:true},
	   		{name:'moTaKhachHang',index:'moTaKhachHang', width:80, sortable:false, editable:true},
	   		{name:'loaiHinhKinhDoanh',index:'loaiHinhKinhDoanh', width:80, sortable:false, editable:true},
	   		{name:'quyMo',index:'quyMo', width:80, sortable:false, editable:true},
	   		{name:'ghiChu',index:'ghiChu', width:80, sortable:false, editable:true},
	   		{name:'chietKhau',index:'chietKhau', width:80, sortable:false, formatter:"number", editable:true},
	   		{name:'nvGiaoHang', index: 'nvGiaoHang', width:80, editable: true, edittype:"select", editoptions:{value: $('#lstNVGiaoHang').val()}},
	   		{name:'trangThai',index:'trangThai', width:80,align:"right", editable:true, edittype:"select", editoptions:{value: "Duyet:Duyệt; Chua duyet: Chưa duyệt; Xoa: Xóa"}},
	   	],
	   	rowNum:10,
	   	rowList:[10,20,30],
	   	pager: '#pDanhSachKhachHang',
	   	sortname: 'maKH',
	    viewrecords: true,
	    loadonce: false,
	    sortorder: "desc",
		jsonReader: {
			repeatitems : false,
			id: "0"
		},
		caption: "Danh sách khách hàng",
		width: '971',
	    height: '100%',
		editurl:"/quanlykhachhang/json/?func=updateKhachHang"
	});
	jQuery("#gridDanhSachKhachHang").jqGrid('navGrid','#pDanhSachKhachHang',
										{
											add:true,
											edit:true,
											del:false
										});
}

$('#cbbTenNV').change(function() {
	$("#gridDanhSachKhachHang").jqGrid().setGridParam({url : '/quanlykhachhang/json/?func=getListKhachHang&maNV=' + $('#cbbTenNV').val() }).trigger('reloadGrid');
	$("#gridDanhSachKhachHang").jqGrid().setGridParam({editurl : '/quanlykhachhang/json/?func=updateKhachHang&maNV=' + $('#cbbTenNV').val() });
});

$(document).ready(function() {
	$('#search').click(function(){$("#gridDanhSachKhachHang").jqGrid().setGridParam({url : '/quanlykhachhang/json/?func=getListKhachHang&tenNV=' + $('#cbbTenNV').val() + '&loaiNV=' + $('#cbbLoaiNV').val()}).trigger('reloadGrid')});
	$('#KinhDoanh').addClass('Active');
    
});